{% extends 'base.html' %}
{% load crispy_forms_tags %}

{% block title %}设置新密码 - {{ block.super }}{% endblock %}

{% block content %}
<div class="row justify-content-center">
    <div class="col-md-6">
        <div class="card">
            <div class="card-header bg-primary text-white">
                <h4 class="card-title mb-0">
                    <i class="fas fa-key"></i> 设置新密码
                </h4>
            </div>
            <div class="card-body">
                {% if validlink %}
                    <form method="post" novalidate>
                        {% csrf_token %}
                        {{ form|crispy }}
                        <div class="d-grid gap-2">
                            <button type="submit" class="btn btn-primary">
                                <i class="fas fa-save"></i> 保存新密码
                            </button>
                        </div>
                    </form>
                {% else %}
                    <div class="alert alert-danger">
                        <p>密码重置链接无效或已过期。</p>
                        <p>请重新申请密码重置。</p>
                    </div>
                    <div class="text-center">
                        <a href="{% url 'accounts:password_reset' %}" class="btn btn-primary">
                            <i class="fas fa-redo"></i> 重新申请
                        </a>
                    </div>
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
document.addEventListener('DOMContentLoaded', function() {
    // 为所有密码输入框添加显示/隐藏功能
    document.querySelectorAll('input[type="password"]').forEach(function(input) {
        // 创建显示/隐藏按钮
        var toggleButton = document.createElement('button');
        toggleButton.type = 'button';
        toggleButton.className = 'btn btn-outline-secondary';
        toggleButton.innerHTML = '<i class="fas fa-eye"></i>';
        toggleButton.style.position = 'absolute';
        toggleButton.style.right = '10px';
        toggleButton.style.top = '50%';
        toggleButton.style.transform = 'translateY(-50%)';
        toggleButton.style.zIndex = '100';
        
        // 包装输入框
        var wrapper = document.createElement('div');
        wrapper.style.position = 'relative';
        input.parentNode.insertBefore(wrapper, input);
        wrapper.appendChild(input);
        wrapper.appendChild(toggleButton);
        
        // 添加点击事件
        toggleButton.addEventListener('click', function() {
            if (input.type === 'password') {
                input.type = 'text';
                toggleButton.innerHTML = '<i class="fas fa-eye-slash"></i>';
            } else {
                input.type = 'password';
                toggleButton.innerHTML = '<i class="fas fa-eye"></i>';
            }
        });
    });
});
</script>
{% endblock %} 